#ifndef _TRIANGLE
#define _TRIANGLE

// INCLUDES --------------------------------------------------------------------
#include "Base.h"
#include "Vector4.h"
#include "Ray.h"

// DEFINES ---------------------------------------------------------------------

// TYPEDEFS --------------------------------------------------------------------
typedef struct
{
  union
  {
    Vector4 A, B, C; // component style
    Vector4 T[3];    // array style
  };
  fp zNear;          // nearest hit distance for ray intersection
} Triangle;

// FUNCTIONS -------------------------------------------------------------------

/* GENERAL:
   d    -> destination
   s    -> source
   size -> array size (0,1 for single elements)

   t    -> arbitrary triangle
   r    -> arbitrary ray
*/

/* clear triangle(s) to standard set:
   
   [A:0,0,0,1
    B:0,1,0,1
	  C:1,0,0,1],

   counterclockwise winding
*/
void TriangleClear    (Triangle *t, ui32 size);
void TriangleCopy     (Triangle *d, Triangle *s, ui32 size); // clone triangle src->dest

bool TriangleIntersect(Triangle *t, Ray *r, ui32 size);      // compute intersection

// POSSIBLY USEFUL:

// check for point-in-triangle (via barycentric coordinates)
//bool TrianglePointInside(Triangle *t, Vector4 *p);

#endif // _TRIANGLE
